//
//  joinQuestListModel.m
//  YuTang
//
//  Created by 葛悦彣 on 2024/8/9.
//

#import "joinQuestListModel.h"
#import "CombinedPunchModel.h"

@implementation joinQuestListModel
+ (NSDictionary *)modelCustomPropertyMapper {
    return @{
        @"ID":@[@"id"],
    };
}

+ (NSDictionary *)modelContainerPropertyGenericClass {
    return @{
        @"handoverProcessModel":[handoverProcessModel class],
        @"pondTissues":[CombinedPunchTissueListModel class],
    };
}

- (NSString *)tissueListStr{
    if(!_tissueListStr){
        NSMutableArray <NSString *>* strArray = [NSMutableArray array];
        for (CombinedPunchTissueListModel * model in self.pondTissues) {
            NSString * str = [NSString stringWithFormat:@"%@ %@",model.pondTissue,model.pondName];
            [strArray addObject:str];
        }
        _tissueListStr = [strArray componentsJoinedByString:@"\n"];
    }
    return _tissueListStr;
}

- (CGFloat)tissueListStrH{
    CGFloat textH = [DTKTool textWithtitle:self.tissueListStr andSize:CGSizeMake(kwt(350), 10000) andFout:kCFont(16)].height;
    if(textH < kwt(16)){
        return kwt(16);
    }
    return textH;
}
-(CGFloat)pondNameH{
    if(_pondNameH == 0){
        _pondNameH = [DTKTool textWithtitle:[NSString stringWithFormat:@"%@ %@",self.pondTissue,self.pondName] andSize:CGSizeMake(kwt(351), 10000) andFout:kCFont(16)].height;
        if(_pondNameH < kwt(16)){
            _pondNameH = kwt(16);
        }
    }
    return _pondNameH;
}
-(CGFloat)cellH{
//    return kwt(170) + self.tissueListStrH + (self.button?kwt(15 + 37):0);
    return kwt(170) + kwt(16) + (self.button?kwt(15 + 37):0);
}
- (CGFloat)JJcellH{
    if(self.voiceUrl.length > 0){
//        return kwt(302) + self.pondNameH;
        return kwt(115 + 56 + 96 + 12 + 10) + self.tissueListStrH;
    }
//    return kwt(246) + self.pondNameH;
    return kwt(115 + 10 + 96 + 12 + 10) + self.tissueListStrH;
}
- (CGFloat)JJFooterH{
    if(self.button){
        return 0;
    }
    if(self.status == 0){
        return 0;
    }
    if(self.handoverProcessModel){
        return kwt(129 + 16);
    } else {
        return kwt(278 + 16);
    }
}
- (void)setVoiceUrl:(NSString *)voiceUrl{
    _voiceUrl = voiceUrl;
    if(voiceUrl.length < 0){
        return;
    }

    AVURLAsset* audioAsset = [AVURLAsset URLAssetWithURL:[NSURL URLWithString:voiceUrl] options: @{AVURLAssetPreferPreciseDurationAndTimingKey:@(YES)}];
    [audioAsset loadValuesAsynchronouslyForKeys:@[@"duration"] completionHandler:^{
        dispatch_async(dispatch_get_main_queue(), ^{
            AVKeyValueStatus status = [audioAsset statusOfValueForKey:@"duration" error:nil];
            if(status == AVKeyValueStatusLoaded){
                CMTime audioDuration = audioAsset.duration;
                float audioDurationSeconds = CMTimeGetSeconds(audioDuration);
                self.voiceDuration = [NSString stringWithFormat:@"%.0f\"",round(audioDurationSeconds)];
                if(self.openDurationBlock){
                    self.openDurationBlock(self.voiceDuration);
                }
            }
        });
    }];
    
}
@end

@implementation handoverProcessModel

- (CGFloat)reasonH{
    if(_reasonH == 0){
        _reasonH = [DTKTool textWithtitle:[NSString stringWithFormat:@"拒绝原因:%@",self.reason] andSize:CGSizeMake(kwt(290), 10000) andFout:kFont(15)].height;
        if(_reasonH < kwt(15)){
            _reasonH = kwt(15);
        }
    }
    return _reasonH;
}
@end
